//
//  LYFCommentTableViewCell.m
//  段子手
//
//  Created by dllo on 16/3/24.
//  Copyright © 2016年 JokesTeam. All rights reserved.
//

#import "LYFCommentTableViewCell.h"

@interface LYFCommentTableViewCell ()

@property (nonatomic, retain) UIImageView *headImg;/**< cell头像图片 */
@property (nonatomic, retain) UILabel *nameLabel;/**< 名字 */
@property (nonatomic, retain) UILabel *commentLabel;/**< 评论文字 */
@property (nonatomic, retain) UIButton *upButton;/**< 点赞 */
@property (nonatomic, assign) BOOL isSelect;
@end
@implementation LYFCommentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCell];
    }
    return self;
}

- (void)dealloc {
    
}

- (void)setModel:(LYFCommentModel *)model {
    _model = model;
    [_headImg sd_setImageWithURL:[NSURL URLWithString:_model.avatar_url]];
    _nameLabel.text = _model.user_name;
    _commentLabel.text = _model.text;
}

/** 创建控件 */
- (void)createCell {
    self.headImg = [[UIImageView alloc] init];
    
    [self.contentView addSubview:_headImg];
    
    self.nameLabel = [[UILabel alloc] init];
    
    [self.contentView addSubview:_nameLabel];
    
    self.commentLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_commentLabel];
    
    self.upButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_upButton];
    
    _isSelect = NO;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _headImg.frame = CGRectMake(10, 10, 40, 40);
    _headImg.layer.cornerRadius = 20;
    _headImg.layer.masksToBounds = YES;
//    _headImg.backgroundColor = [UIColor orangeColor];
    
    
    NSDictionary *textDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], NSFontAttributeName, nil];
    CGRect rect = [_model.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 80, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:textDic context:nil];
    
    
    _nameLabel.frame = CGRectMake(60, 10, 200, 30);
    _nameLabel.textColor = [UIColor grayColor];
    _nameLabel.font = [UIFont systemFontOfSize:15];
//    _nameLabel.backgroundColor = [UIColor redColor];
    
    _commentLabel.frame = CGRectMake(60, 50, SCREEN_WIDTH - 80, rect.size.height);
    _commentLabel.font = [UIFont systemFontOfSize:17];
    _commentLabel.numberOfLines = 0;
//    _commentLabel.backgroundColor = [UIColor grayColor];
    
    _upButton.frame = CGRectMake(320, 10, 30, 30);
    [_upButton setImage:[UIImage imageNamed:@"RC32NLI__LBBJR]ET5I%D{5.png"] forState:UIControlStateNormal];
    [_upButton addTarget:self action:@selector(upButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    

}


/** 点赞方法 */
- (void)upButtonAction:(UIButton *) button {
    if (_isSelect == YES) {
        [_upButton setImage:[UIImage imageNamed:@"LSIJ7U8~XLPV(1HNCD9DYJO.png"] forState:UIControlStateNormal];
    } else {
        [_upButton setImage:[UIImage imageNamed:@"RC32NLI__LBBJR]ET5I%D{5.png"] forState:UIControlStateNormal];
    }
    _isSelect =!_isSelect;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
